package com.lemner.ke.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;
/**
 * 知 库
 * ViewPager适配器
 * @author raintea
 * @date 2018/9/20
 */
public class KnowledageViewPageAdapter extends FragmentPagerAdapter {

    private List<Fragment> fragments;
    private List<String> titles;
    public KnowledageViewPageAdapter(FragmentManager fm) {
        super(fm);
    }

    public void setFragments(List<Fragment> fragments,List<String> titles) {
        this.fragments = fragments;
        this.titles =titles;
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem(int position) {
        return fragments == null ? null : fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments == null ? 0 : fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles == null ? "":titles.get(position);
    }
}
